package org.creativor.rayson.common;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.PipedInputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The class <code>ClientSessionTest</code> contains tests for the class
 * <code>{@link ClientSession}</code>.
 * <p>
 * Copyright Creativor Studio (c) 2011
 * 
 * @generatedBy CodePro at 11-5-7 上午3:08
 * @author Nick Zhang
 * @version $Revision: 1.0 $
 */
public class ClientSessionTest
{
	/**
	 * Launch the test.
	 * 
	 * @param args
	 *            the command line arguments
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	public static void main(String[] args)
	{
		new org.junit.runner.JUnitCore().run(ClientSessionTest.class);
	}
	
	/**
	 * Perform pre-test initialization.
	 * 
	 * @throws Exception
	 *             if the initialization fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Before
	public void setUp() throws Exception
	{
		// TODO: add additional set up code here
	}
	
	/**
	 * Perform post-test clean-up.
	 * 
	 * @throws Exception
	 *             if the clean-up fails for some reason
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@After
	public void tearDown() throws Exception
	{
		// TODO: add additional tear down code here
	}
	
	/**
	 * Run the ClientSession() constructor test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testClientSession_1() throws Exception
	{
		
		ClientSession result = new ClientSession();
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals(null, result.getServiceName());
		assertEquals(0L, result.getLastAccessedTime());
		assertEquals((byte) 0, result.getClientVersion());
		assertEquals(null, result.getPeerAddress());
		assertEquals((short) 0, result.getProxyVersion());
	}
	
	/**
	 * Run the ClientSession(byte,short,long,String,long,InetSocketAddress)
	 * constructor test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testClientSession_2() throws Exception
	{
		byte version = (byte) 1;
		short proxyVersion = (short) 1;
		long sessionId = 1L;
		String serviceName = "";
		long creationTime = 1L;
		InetAddress peerAddress = (new InetSocketAddress(1)).getAddress();
		
		ClientSession result = new ClientSession(version, proxyVersion, serviceName, peerAddress);
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals(
				"{id: 1, version: 1, proxy version: 1, server address: 0.0.0.0/0.0.0.0:1, service name: , creationTime: 1}",
				result.toString());
		assertEquals("", result.getServiceName());
		assertEquals(1L, result.getLastAccessedTime());
		assertEquals((byte) 1, result.getClientVersion());
		assertEquals((short) 1, result.getProxyVersion());
	}
	
	/**
	 * Run the ClientSession
	 * fromPortableSession(ClientSession,InetSocketAddress,byte) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testFromPortableSession_1() throws Exception
	{
		ClientSession portable =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		InetAddress peerAddress = (new InetSocketAddress(1)).getAddress();
		byte clientVersion = (byte) 1;
		
		ClientSession result =
				ClientSession.fromPortableSession(portable, peerAddress, clientVersion);
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals(
				"{id: 1, version: 1, proxy version: 1, server address: 0.0.0.0/0.0.0.0:1, service name: , creationTime: 1}",
				result.toString());
		assertEquals("", result.getServiceName());
		assertEquals(1L, result.getLastAccessedTime());
		assertEquals((byte) 1, result.getClientVersion());
		assertEquals((short) 1, result.getProxyVersion());
	}
	
	/**
	 * Run the byte getClientVersion() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testGetClientVersion_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		
		byte result = fixture.getClientVersion();
		
		// TODO: add additional test code here
		assertEquals((byte) 1, result);
	}
	
	/**
	 * Run the long getCreationTime() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testGetCreationTime_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		
		long result = fixture.getLastAccessedTime();
		
		// TODO: add additional test code here
		assertEquals(1L, result);
	}
	
	/**
	 * Run the InetSocketAddress getPeerAddress() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testGetPeerAddress_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		
		InetAddress result = fixture.getPeerAddress();
		
		// TODO: add additional test code here
		assertNotNull(result);
		assertEquals("0.0.0.0/0.0.0.0:1", result.toString());
		assertEquals("0.0.0.0", result.getHostName());
	}
	
	/**
	 * Run the short getProxyVersion() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testGetProxyVersion_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		
		short result = fixture.getProxyVersion();
		
		// TODO: add additional test code here
		assertEquals((short) 1, result);
	}
	
	/**
	 * Run the String getServiceName() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testGetServiceName_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		
		String result = fixture.getServiceName();
		
		// TODO: add additional test code here
		assertEquals("", result);
	}
	
	/**
	 * Run the void read(DataInput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test(expected = java.io.IOException.class)
	public void testRead_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataInput in = new DataInputStream(new PipedInputStream());
		
		fixture.read(in);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void read(DataInput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test(expected = java.io.IOException.class)
	public void testRead_2() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataInput in = new DataInputStream(new PipedInputStream());
		
		fixture.read(in);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void read(DataInput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test(expected = java.io.IOException.class)
	public void testRead_3() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataInput in = new DataInputStream(new PipedInputStream());
		
		fixture.read(in);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void read(DataInput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test(expected = java.io.IOException.class)
	public void testRead_4() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataInput in = new DataInputStream(new PipedInputStream());
		
		fixture.read(in);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void read(DataInput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test(expected = java.io.IOException.class)
	public void testRead_5() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataInput in = new DataInputStream(new PipedInputStream());
		
		fixture.read(in);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the String toString() method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testToString_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		
		String result = fixture.toString();
		
		// TODO: add additional test code here
		assertEquals(
				"{id: 1, version: 1, proxy version: 1, server address: 0.0.0.0/0.0.0.0:1, service name: , creationTime: 1}",
				result);
	}
	
	/**
	 * Run the void write(DataOutput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testWrite_1() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataOutput out = new DataOutputStream(new ByteArrayOutputStream());
		
		fixture.write(out);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void write(DataOutput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testWrite_2() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataOutput out = new DataOutputStream(new ByteArrayOutputStream());
		
		fixture.write(out);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void write(DataOutput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testWrite_3() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataOutput out = new DataOutputStream(new ByteArrayOutputStream());
		
		fixture.write(out);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void write(DataOutput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testWrite_4() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataOutput out = new DataOutputStream(new ByteArrayOutputStream());
		
		fixture.write(out);
		
		// TODO: add additional test code here
	}
	
	/**
	 * Run the void write(DataOutput) method test.
	 * 
	 * @throws Exception
	 * 
	 * @generatedBy CodePro at 11-5-7 上午3:08
	 */
	@Test
	public void testWrite_5() throws Exception
	{
		ClientSession fixture =
				new ClientSession((byte) 1, (short) 1, "", (new InetSocketAddress(1)).getAddress());
		DataOutput out = new DataOutputStream(new ByteArrayOutputStream());
		
		fixture.write(out);
		
		// TODO: add additional test code here
	}
}
